home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / userbox / publicdomain / delitracker_ii / bonus / delistartup / source / delistartup.asm
Assembly Source File  |  1994-08-10  |  8KB  |  418 lines

  1. ***
  2. *** Startup code for DeliTracker genies (and players too if necessary) programmed in SAS/C
  3. *** which is a somewhat more pleasant experience than doing the same in assembly language...
  4. ***
  5. *** $VER: delistartup.asm 2.0 (10.08.94) by Necro\Banana Dezign
  6. ***
  7. *** Code is VERY inspired by the SAS/C startup code (c.a)
  8. ***
  9. *** To assemble: asm -u delistartup.asm
  10. ***
  11.  
  12.     include    "exec/types.i"
  13.     include    "exec/alerts.i"
  14.     include    "exec/nodes.i"
  15.     include    "exec/lists.i"
  16.     include    "exec/ports.i"
  17.     include    "exec/libraries.i"
  18.     include    "exec/tasks.i"
  19.     include    "exec/memory.i"
  20.     include    "exec/execbase.i"
  21.     include    "exec/funcdef.i"
  22.     include    "exec/exec_lib.i"
  23.     include    "dos/dosextens.i"
  24.     include    "dos/dos_lib.i"
  25.     include    "utility/tagitem.i"
  26.     include    "misc/DeliPlayer.i"
  27.     include    "necro/macros.i"
  28.  
  29.  
  30.     xdef    _XCEXIT        * exit(code) is standard way to leave C
  31.     xdef    @_XCEXIT
  32.  
  33.     xref    DeliTags
  34.     xref    LinkerDB    * linker defined base value
  35.     xref    _BSSBAS        * linker defined base of BSS
  36.     xref    _BSSLEN        * linker defined length of BSS
  37.     xref    __stack
  38.  
  39. ;;;
  40. ;;;   Stack map.
  41. ;;;
  42.       OFFSET  0
  43.            ds.b    4
  44. savereg    ds.b    13*4
  45. stackbtm   ds.b    4
  46.  
  47.  
  48.  
  49.     section    text,code
  50.  
  51.     xref    __main
  52.     xref    __fpinit
  53.     xref    __fpterm
  54.  
  55.     bra.w    errorMsg
  56.     dc.b    "DELIRIUM"
  57.     dc.l    DeliTags
  58.  
  59. errorMsg    move.l    4.w,a6
  60.         move.l    ThisTask(a6),a3
  61.         tst.l    pr_CLI(a3)
  62.         beq    .wb
  63.  
  64.         lea    dosName(pc),a1
  65.         moveq    #36,d0
  66.         LVOEXE    OpenLibrary
  67.         tst.l    d0
  68.         bne.s    .ok
  69.         moveq    #20,d0
  70.         rts
  71. .ok        move.l    d0,a6
  72.         lea    errorText(pc),a0
  73.         move.l    a0,d1
  74.         LVO    PutStr
  75.         move.l    a6,a1
  76.         LVOEXE    CloseLibrary
  77.         moveq    #20,d0
  78.         rts
  79.  
  80. .wb        lea    pr_MsgPort(a3),a0
  81.         LVO    WaitPort
  82.         lea    pr_MsgPort(a3),a0
  83.         LVO    GetMsg
  84.         move.l    d0,d7
  85.  
  86.         lea    dosName(pc),a1
  87.         moveq    #36,d0
  88.         LVOEXE    OpenLibrary
  89.         tst.l    d0
  90.         bne.s    .wok
  91.         moveq    #20,d0
  92.         bra    .end
  93. .wok        move.l    d0,a6
  94.         lea    errorStream(pc),a0
  95.         move.l    a0,d1
  96.         move.l    #MODE_OLDFILE,d2
  97.         LVO    Open
  98.         move.l    d0,d6
  99.         beq    .errclose
  100.         move.l    d6,d1
  101.         lea    errorText(pc),a0
  102.         move.l    a0,d2
  103.         LVO    FPuts
  104.         move.l    d6,d1
  105.         lea    pressText(pc),a0
  106.         move.l    a0,d2
  107.         LVO    FPuts
  108.         move.l    d6,d1
  109.         LVO    FGetC
  110.         move.l    d6,d1
  111.         LVO    Close
  112. .errclose    move.l    a6,a1
  113.         LVOEXE    CloseLibrary
  114.         moveq    #20,d0
  115.  
  116. .end        move.l    d0,-(sp)
  117.         move.l    d7,a1
  118.         LVOEXE    Forbid
  119.         move.l    d7,a1
  120.         LVO    ReplyMsg
  121.         move.l    (sp)+,d0
  122.         rts
  123.  
  124. *** process entry code starts here - this is the entry point when DeliTracker launches us
  125.  
  126.     xdef    @initCode
  127.     xdef    initCode
  128.  
  129. @initCode
  130. initCode    movem.l    d1-d6/a0-a6,-(a7)
  131.  
  132.         lea    LinkerDB,a4
  133.         move.l    4.w,a6
  134.         move.l    a7,_StackPtr(a4)
  135.         move.l    a6,SysBase(a4)
  136.  
  137. *** get stacksize (we don't allocate bigger stacks as the tag DTG_StackSize should be good enough...)
  138.  
  139.         move.l    ThisTask(a6),a3
  140.         move.l    a7,d0
  141.         sub.l    TC_SPLOWER(a3),d0
  142.  
  143. *** set __base for stack checking
  144.  
  145.         move.l    a7,d1
  146.         sub.l    d0,d1
  147.         add.l    #128,d1
  148.         move.l    d1,__base(a4)
  149.  
  150.         move.l    ThisTask(a6),a3
  151.  
  152. *** get available libraries from DeliBase
  153.  
  154.         move.l    DeliBase,a0
  155.         move.l    dtg_DOSBase(a0),DOSBase(a4)
  156.         move.l    dtg_IntuitionBase(a0),IntuitionBase(a4)
  157.         move.l    dtg_GfxBase(a0),GfxBase(a4)
  158.         move.l    dtg_GadToolsBase(a0),GadToolsBase(a4)
  159.         move.l    dtg_AslBase(a0),AslBase(a4)
  160.  
  161. *** here would be the CLI/WB argument collection (WBMsgs, etc.), but DeliTracker uses none of that...
  162. *** so note that main goes as follows: main(void) - not main(argc,argv) !!
  163.  
  164.         move.l    pr_CurrentDir(a3),__curdir(a4)
  165.         move.l    LN_NAME(a3),_ProgramName(a4)    * use task name as program name
  166.  
  167. *** the startup
  168.  
  169. main        jsr    __fpinit(pc)        * init floating point
  170.         tst.l    d0
  171.         bne.s    exit2
  172.         jsr    __main(pc)        * call C entry point
  173.         moveq    #0,d0            * set successful status
  174.         bra.s    exit2
  175.  
  176. XCEXIT
  177. _XCEXIT        move.l    4(a7),d0        * get return code
  178.  
  179. @XCEXIT
  180. @_XCEXIT
  181. exit2        move.l    _StackPtr(a4),a7
  182.         move.l    d0,-(a7)
  183.  
  184.         move.l    _ONEXIT(a4),d0        * call any exit trap functions
  185.         beq.s    exit3
  186.         move.l    d0,a0
  187.         jsr    (a0)
  188. exit3        jsr    __fpterm(pc)        * clean up floating point
  189.  
  190.         move.l    (a7)+,d0        * restore return code
  191. return        movem.l    (a7)+,d1-d6/a0-a6
  192.         rts
  193.  
  194. ***
  195. *** Here are the C stubs for the DeliTracker interface functions
  196. ***
  197. *** They're all mostly the same thing repeated over and over with different offsets, but it was the
  198. *** best solution I could come up with at the time. I don't trust C to handle the calling directly.
  199. ***
  200.  
  201.     xdef    dt_GetListDataPos
  202.  
  203. dt_GetListDataPos    * dtg_GetListData had to be split up as you can't return two parameters
  204.         bsr.s    dt_GetListDataSize
  205.         move.l    a0,d0
  206.         rts
  207.  
  208.     xdef    dt_GetListDataSize
  209.  
  210. dt_GetListDataSize
  211.         move.l    a5,-(a7)
  212.         move.l    DeliBase,a5
  213.         move.l    dtg_GetListData(a5),a0
  214.         jsr    (a0)
  215.         move.l    (a7)+,a5
  216.         rts
  217.  
  218.     xdef    dt_LoadFile
  219.  
  220. dt_LoadFile    move.l    a5,-(a7)
  221.         move.l    DeliBase,a5
  222.         move.l    dtg_LoadFile(a5),a0
  223.         jsr    (a0)
  224.         move.l    (a7)+,a5
  225.         rts
  226.  
  227.     xdef    dt_CopyDir
  228.  
  229. dt_CopyDir    move.l    a5,-(a7)
  230.         move.l    DeliBase,a5
  231.         move.l    dtg_CopyDir(a5),a0
  232.         jsr    (a0)
  233.         move.l    (a7)+,a5
  234.         rts
  235.  
  236.     xdef    dt_CopyFile
  237.  
  238. dt_CopyFile    move.l    a5,-(a7)
  239.         move.l    DeliBase,a5
  240.         move.l    dtg_CopyFile(a5),a0
  241.         jsr    (a0)
  242.         move.l    (a7)+,a5
  243.         rts
  244.  
  245.     xdef    dt_CopyString
  246.  
  247. dt_CopyString    move.l    a5,-(a7)
  248.         move.l    DeliBase,a5
  249.         move.l    dtg_CopyString(a5),a0
  250.         jsr    (a0)
  251.         move.l    (a7)+,a5
  252.         rts
  253.  
  254.     xdef    dt_AudioAlloc
  255.  
  256. dt_AudioAlloc    move.l    a5,-(a7)
  257.         move.l    DeliBase,a5
  258.         move.l    dtg_AudioAlloc(a5),a0
  259.         jsr    (a0)
  260.         move.l    (a7)+,a5
  261.         rts
  262.  
  263.     xdef    dt_AudioFree
  264.  
  265. dt_AudioFree    move.l    a5,-(a7)
  266.         move.l    DeliBase,a5
  267.         move.l    dtg_AudioFree(a5),a0
  268.         jsr    (a0)
  269.         move.l    (a7)+,a5
  270.         rts
  271.  
  272.     xdef    dt_StartInt
  273.  
  274. dt_StartInt    move.l    a5,-(a7)
  275.         move.l    DeliBase,a5
  276.         move.l    dtg_StartInt(a5),a0
  277.         jsr    (a0)
  278.         move.l    (a7)+,a5
  279.         rts
  280.  
  281.     xdef    dt_StopInt
  282.  
  283. dt_StopInt    move.l    a5,-(a7)
  284.         move.l    DeliBase,a5
  285.         move.l    dtg_StopInt(a5),a0
  286.         jsr    (a0)
  287.         move.l    (a7)+,a5
  288.         rts
  289.  
  290.     xdef    dt_SongEnd
  291.  
  292. dt_SongEnd    move.l    a5,-(a7)
  293.         move.l    DeliBase,a5
  294.         move.l    dtg_SongEnd(a5),a0
  295.         jsr    (a0)
  296.         move.l    (a7)+,a5
  297.         rts
  298.  
  299.     xdef    dt_CutSuffix
  300.  
  301. dt_CutSuffix    move.l    a5,-(a7)
  302.         move.l    DeliBase,a5
  303.         move.l    dtg_CutSuffix(a5),a0
  304.         jsr    (a0)
  305.         move.l    (a7)+,a5
  306.         rts
  307.  
  308.     xdef    dt_SetTimer
  309.  
  310. dt_SetTimer    move.l    a5,-(a7)
  311.         move.l    DeliBase,a5
  312.         move.l    dtg_SetTimer(a5),a0
  313.         jsr    (a0)
  314.         move.l    (a7)+,a5
  315.         rts
  316.  
  317.     xdef    dt_WaitAudioDMA
  318.  
  319. dt_WaitAudioDMA
  320.         move.l    a5,-(a7)
  321.         move.l    DeliBase,a5
  322.         move.l    dtg_WaitAudioDMA(a5),a0
  323.         jsr    (a0)
  324.         move.l    (a7)+,a5
  325.         rts
  326.  
  327.     xdef    dt_LockScreen
  328.  
  329. dt_LockScreen    move.l    a5,-(a7)
  330.         move.l    DeliBase,a5
  331.         move.l    dtg_LockScreen(a5),a0
  332.         jsr    (a0)
  333.         move.l    (a7)+,a5
  334.         rts
  335.  
  336.     xdef    dt_UnlockScreen
  337.  
  338. dt_UnlockScreen
  339.         move.l    a5,-(a7)
  340.         move.l    DeliBase,a5
  341.         move.l    dtg_UnlockScreen(a5),a0
  342.         jsr    (a0)
  343.         move.l    (a7)+,a5
  344.         rts
  345.  
  346.     xdef    dt_NotePlayer
  347.  
  348. dt_NotePlayer    move.l    a5,-(a7)
  349.         move.l    DeliBase,a5
  350.         move.l    dtg_NotePlayer(a5),a0
  351.         jsr    (a0)
  352.         move.l    (a7)+,a5
  353.         rts
  354.  
  355.     xdef    dt_AllocListData
  356.  
  357. dt_AllocListData
  358.         move.l    a5,-(a7)
  359.         move.l    DeliBase,a5
  360.         move.l    dtg_AllocListData(a5),a0
  361.         jsr    (a0)
  362.         move.l    (a7)+,a5
  363.         rts
  364.  
  365.     xdef    dt_FreeListData
  366.  
  367. dt_FreeListData
  368.         move.l    a5,-(a7)
  369.         move.l    DeliBase,a5
  370.         move.l    dtg_FreeListData(a5),a0
  371.         jsr    (a0)
  372.         move.l    (a7)+,a5
  373.         rts
  374.  
  375. *** just some strings for the error routine
  376.  
  377. dosName        dc.b    "dos.library",0
  378. errorText    dc.b    "This program is a DeliTracker genie, and can only be started from DeliTracker.",10,0
  379. pressText    dc.b    10,"Press RETURN...",0
  380. errorStream    dc.b    "CON:160/14/320/64/Error Requester/AUTO/CLOSE",0
  381.  
  382. *** variable space
  383.  
  384.     section __MERGED,bss
  385.  
  386.     xdef    NULL,SysBase,DOSBase,IntuitionBase,GfxBase,GadToolsBase,AslBase
  387.     xref    _FPERR
  388.  
  389.     xref    _WBenchMsg
  390.     xref    __curdir
  391.     xref    _OSERR,_SIGFPE,_ONERR,_ONEXIT,_ONBREAK
  392.     xref    _SIGINT
  393.     xref    _ProgramName,_StackPtr,__base
  394.  
  395.     xdef    DeliBase
  396.     xdef    DeliPort
  397.  
  398. NULL        ds.b    4
  399. DOSBase        ds.b    4
  400. IntuitionBase    ds.b    4
  401. GfxBase        ds.b    4
  402. GadToolsBase    ds.b    4
  403. AslBase        ds.b    4
  404. SysBase        ds.b    4
  405. mystk_Lower    ds.b    4
  406. mystk_Upper    ds.b    4
  407. mystk_Pointer    ds.b    4
  408.  
  409. DeliBase    ds.b    4
  410. DeliPort    ds.b    4
  411.  
  412. newstack    ds.b    4
  413. newstacksize    ds.b    4
  414.  
  415.  
  416.     end
  417.  
  418.